package cn.com.jsepc.rep.process;


import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.Hashtable;
import javax.servlet.ServletException;



import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

//import cn.com.jsepc.rep.comm.Common;
import cn.com.jsepc.appframe.common.domain.Code;
import cn.com.jsepc.rep.comm.Common;
import cn.com.jsepc.rep.comm.ConstUtil;
import cn.com.jsepc.rep.vo.PmangaeVO;

import com.jarp.db.DAO;

public class process_manage {
 	public synchronized String add_manage(String itemJsonInfo)
			throws ServletException {
		try {
			JSONObject jsonObject = new JSONObject(itemJsonInfo);
			DAO dao = new DAO();
			PmangaeVO vo = new PmangaeVO();
			vo.setPcode(jsonObject.getString("Code"));
			vo.setPname(jsonObject.getString("Name"));			
			vo.setPdesc(jsonObject.getString("Desc"));
			vo.setpWin(jsonObject.getString("Win"));
			
			if(vo.getpWin().equals("01")){
				String seq_bianma = "select * from tb_domain where domainCode = '"+ vo.getPcode() +"'";
				Vector v = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
				if(v != null){
					System.out.println("数据库中有此编码");
					return "haven";
					} else {
						String seq_mingcheng = "select * from tb_domain where domainName = '"+ vo.getPname() +"'";
						Vector v1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
						if(v1 != null){
							return "haven1";
						} else {			
							Common comm = new Common();
							String proval = comm.getSeqStr("SEQ_TB_DOMAIN");
							
							String add_seq = "insert into tb_domain(" + "domainID, " + "domainCode, " + "domainName, "
									+ "domainDesc) values("
									+ proval +",'"
									+ vo.getPcode()
									+ "','"
									+ vo.getPname()
									+ "','"
									+ vo.getPdesc()
									+ "')";
						int bRet = dao.execCommand(ConstUtil.DBNAME, add_seq);
						if (bRet == 1) {
							return "ok";
						} else {
							return "wrong";
						}
					} 
				}
				}else if(vo.getpWin().equals("1")){//流程
			String seq_bianma = "select * from tb_process where processCode = '"+ vo.getPcode() +"'";
			Vector v = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
			if(v != null){
				return "haven";
				} else {
					String seq_mingcheng = "select * from tb_process where processName = '"+ vo.getPname() +"'";
					Vector v1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
					if(v1 != null){
						return "haven1";
					} else {	
				        String [] myparentID=jsonObject.getString("parentID").split("_");
				        String parentID = myparentID[myparentID.length-1];	
						vo.setPlink(parentID);
						
						Common comm = new Common();
						String processval = comm.getSeqStr("SEQ_TB_PROCESS");
						
						String add_seq = "insert into tb_process(" + "processID, " + "processCode, "+ "processName, "
								+ "processDesc," + "domainID) values("
								+ processval +",'"
								+ vo.getPcode()
								+ "','"
								+ vo.getPname()
								+ "','"
								+ vo.getPdesc()
								+ "',"
								+ vo.getPlink()
								+ ")";
					int bRet = dao.execCommand(ConstUtil.DBNAME, add_seq);
					if (bRet == 1) {
						return "ok";
					} else {
						return "wrong";
					}
				} }
			}else if(vo.getpWin().equals("10")){//流程周期
				String seq_bianma = "select * from tb_process_lifecycle where lifecycleCode = '"+ vo.getPcode() +"'";
				Vector v = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
				if(v != null){
					return "haven";
					} else {
						String seq_mingcheng = "select * from tb_process_lifecycle where lifecycleName = '"+ vo.getPname() +"'";
						Vector v1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
						if(v1 != null){
							return "haven1";
						} else {	
					        String [] myparentID=jsonObject.getString("parentID").split("_");
					        String parentID = myparentID[myparentID.length-1];	
							vo.setPlink(parentID);
							
							Common comm = new Common();
							String linkval = comm.getSeqStr("SEQ_proc_lifecycle");

							String add_seq = "insert into tb_process_lifecycle(" + "lifecycleID, " + "lifecycleCode, " + "lifecycleName, "+ "lifecycleDesc, "
									+ "processID) values("
									+ linkval +",'"
									+ vo.getPcode()
									+ "','"
									+ vo.getPname()
									+ "','"
									+ vo.getPdesc()
									+ "',"
									+ vo.getPlink()
									+ ")";
						int bRet = dao.execCommand(ConstUtil.DBNAME, add_seq);
						if (bRet == 1) {
							return "ok";
						} else {
							return "wrong";
						}
					} 
			}
				}else if(vo.getpWin().equals("3")){//环节
//				String seq_bianma = "select * from tb_link where linkcode = '"+ vo.getPcode() +"'";
//				Vector v = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
//				if(v != null){
//					return "haven";
//					} else {
						String seq_mingcheng = "select * from tb_link where linkname = '"+ vo.getPname() +"'";
						Vector v1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
						if(v1 != null){
							return "haven1";
						} else {	
					        String [] myparentID=jsonObject.getString("parentID").split("_");
					        String parentID = myparentID[myparentID.length-1];	
							vo.setPlink(parentID);
							
							Common comm = new Common();
							String linkval = comm.getSeqStr("SEQ_TB_LINK");

							String add_seq = "insert into tb_link(" + "linkid, " + "linkcode, "+ "linkname, "+ "linkDesc, "
									+ "lifecycleID) values("
									+ linkval +",'"
									+ vo.getPcode()
									+ "','"
									+ vo.getPname()
									+ "','"
									+ vo.getPdesc()
									+ "',"
									+ vo.getPlink()
									+ ")";
						int bRet = dao.execCommand(ConstUtil.DBNAME, add_seq);
						if (bRet == 1) {
							return "ok";
						} else {
							return "wrong";
						}
					} 
			}else if(vo.getpWin().equals("4")){//关注点
				String seq_bianma = "select * from tb_point where pointCode = '"+ vo.getPcode() +"'";
				Vector v = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
				if(v != null){
					return "haven";
					} else {
						String seq_mingcheng = "select * from tb_point where pointName = '"+ vo.getPname() +"'";
						Vector v1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
						if(v1 != null){
							return "haven1";
						} else {			
					        String [] myparentID=jsonObject.getString("parentID").split("_");
					        String parentID = myparentID[myparentID.length-1];	
							vo.setPlink(parentID);
							
							Common comm = new Common();
							String pointval = comm.getSeqStr("SEQ_TB_POINT");

							String add_seq = "insert into tb_point(" + "pointID, " + "pointCode, "+ "pointName, "+ "pointDesc, "
									+ "linkID) values("
									+ pointval +",'"
									+ vo.getPcode()
									+ "','"
									+ vo.getPname()
									+ "','"
									+ vo.getPdesc()
									+ "',"
									+ vo.getPlink()
									+ ")";
						int bRet = dao.execCommand(ConstUtil.DBNAME, add_seq);
						if (bRet == 1) {
							return "ok";
						} else {
							return "wrong";
						}
					} }
							
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
			return "wrong";
		}
		return "end";
	}

	public synchronized String edit_manage(String itemJsonInfo)
			throws ServletException {
		try {
			JSONObject jsonObject = new JSONObject(itemJsonInfo);
			DAO dao = new DAO();
			PmangaeVO vo = new PmangaeVO();
			vo.setpID(jsonObject.getString("p_id"));
			vo.setPcode(jsonObject.getString("Code"));
			vo.setPname(jsonObject.getString("Name"));
			vo.setPdesc(jsonObject.getString("Desc"));
			vo.setpWin(jsonObject.getString("Win"));
			if(vo.getpWin().equals("01")){
				String seq_bianma = "select * from tb_domain where domainCode = '" + vo.getPcode() +"' and domainID != " + vo.getpID();
						Vector v_ = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
						if(v_ != null){
							return "haven";
						} else {
//						String seq_mingcheng = "select * from tb_domain where domainName = '"+ vo.getPname() +"' and domainID != " + vo.getpID();
//						Vector v_1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
//						if(v_1 != null){
//							return "haven1";
//						} else {

						String sql = "update tb_domain set domainCode='" + vo.getPcode() + "',domainName='" + vo.getPname() + "',domainDesc='" + vo.getPdesc()
								+"' where domainID = "
								+ vo.getpID();
						int bRet = dao.execCommand(ConstUtil.DBNAME, sql);
						if (bRet == 1) {
							return "ok";
						} else {
							return "wrong";
						}
//						}
			}}
			if(vo.getpWin().equals("1")){//流程
			String seq_bianma = "select * from tb_process where PROCESSCODE = '"+ vo.getPcode() +"' and PROCESSID != " + vo.getpID();
	//		System.out.println(seq_bianma);
			Vector v_ = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
			if(v_ != null){
				return "haven";
			} else {
//			String seq_mingcheng = "select * from tb_process where PROCESSNAME = '"+ vo.getPname() +"' and PROCESSID != " + vo.getpID();
//			Vector v_1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
//			if(v_1 != null){
//				return "haven1";
//			} else {
			vo.setPlink(jsonObject.getString("parentID"));
			String sql = "update tb_process set PROCESSCODE='" + vo.getPcode()
					+ "',PROCESSNAME='" + vo.getPname() + "',PROCESSDESC='" + vo.getPdesc() +"',domainID = "+ vo.getPlink()
					+ " where PROCESSID = "
					+ vo.getpID();
			int bRet = dao.execCommand(ConstUtil.DBNAME, sql);
			if (bRet == 1) {
				return "ok";
			} else {
				return "wrong";
//			}
			}}
		}else if(vo.getpWin().equals("10")){
			String seq_bianma = "select * from tb_process_lifecycle where lifecycleCode = '"+ vo.getPcode() +"' and lifecycleID != " + vo.getpID();
			//		System.out.println(seq_bianma);
					Vector v_ = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
					if(v_ != null){
						return "haven";
					} else {
//					String seq_mingcheng = "select * from tb_process_lifecycle where lifecycleName = '"+ vo.getPname() +"' and lifecycleID != " + vo.getpID();
//					System.out.print(seq_mingcheng);
//					Vector v_1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
//					if(v_1 != null){
//						return "haven1";
//					} else {
					vo.setPlink(jsonObject.getString("parentID"));

					String sql = "update tb_process_lifecycle set lifecycleCode='" + vo.getPcode() + "',lifecycleName='" + vo.getPname() + "',lifecycleDesc='" + vo.getPdesc()+ "',processID=" + vo.getPlink()
							+" where lifecycleID = "
							+ vo.getpID();
					int bRet = dao.execCommand(ConstUtil.DBNAME, sql);
					if (bRet == 1) {
						return "ok";
					} else {
						return "wrong";
					}
//					}
				}}else if(vo.getpWin().equals("4")){//环节
			String seq_bianma = "select * from tb_link where LINKCODE = '"+ vo.getPcode() +"' and LINKID != " + vo.getpID();
	//		System.out.println(seq_bianma);
			Vector v_ = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
			if(v_ != null){
				return "haven";
			} else {
//			String seq_mingcheng = "select * from tb_link where LINKNAME = '"+ vo.getPname() +"' and LINKID != " + vo.getpID();
//			Vector v_1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
//			if(v_1 != null){
//				System.out.println("数据库中有此名称");
//				return "haven1";
//			} else {
			vo.setPlink(jsonObject.getString("parentID"));

			String sql = "update tb_link set LINKCODE='" + vo.getPcode()
					+ "',LINKNAME='" + vo.getPname() + "',LINKDESC='" + vo.getPdesc()+ "',lifecycleID=" + vo.getPlink()
					+" where LINKID = "
					+ vo.getpID();
//			System.out.println(sql);
			int bRet = dao.execCommand(ConstUtil.DBNAME, sql);
			if (bRet == 1) {
				return "ok";
			} else {
				return "wrong";
//			}
			}}
					
		}else if(vo.getpWin().equals("5")){//关注点
			String seq_bianma = "select * from tb_point where POINTCODE = '"+ vo.getPcode() +"' and POINTID != " + vo.getpID();
//			System.out.println(seq_bianma);
			Vector v_ = dao.getDataSet(ConstUtil.DBNAME, seq_bianma);
			if(v_ != null){
				return "haven";
			} else {
//			String seq_mingcheng = "select * from tb_point where POINTNAME = '"+ vo.getPname() +"' and POINTID != " + vo.getpID();
//			Vector v_1 = dao.getDataSet(ConstUtil.DBNAME, seq_mingcheng);
//			if(v_1 != null){
//				System.out.println("数据库中有此名称");
//				return "haven1";
//			} else {
			vo.setPlink(jsonObject.getString("parentID"));

			String sql = "update tb_point set POINTCODE='" + vo.getPcode()
					+ "',POINTNAME='" + vo.getPname() + "',POINTDESC='" + vo.getPdesc()+ "',LINKID=" + vo.getPlink()
					+" where POINTID = "
					+ vo.getpID();
//			System.out.println(sql);
			int bRet = dao.execCommand(ConstUtil.DBNAME, sql);
			if (bRet == 1) {
				return "ok";
			} else {
				return "wrong";
			}
			}}
//		}
			} catch (RuntimeException e) {
			e.printStackTrace();
			return "wrong";
		}
			return "end";
	}

	public synchronized String del(String itemJsonInfo)
			throws ServletException {
		try {
			ArrayList<String> del_record = new ArrayList<String>();
			JSONObject jsonObject = new JSONObject(itemJsonInfo);
			DAO dao = new DAO();
			String deep = jsonObject.getString("deep");
			if(deep.equals("")||deep.equals("0")){
				String seq = "select * from TB_PROCESS where DOMAINID = "+ jsonObject.getInt("pID");
	//			System.out.println(seq);
				Vector v = dao.getDataSet(ConstUtil.DBNAME, seq);
				if(v != null){
					return "have_xia";
				} 
				String sql_del = "delete from TB_DOMAIN where DOMAINID = " + jsonObject.getInt("pID");
				del_record.add(sql_del);
				
//				String seq_rep = "select * from TB_DOMAIN_REP where DOMAINID = "+ jsonObject.getInt("pID");
//				Vector v_rep = dao.getDataSet(ConstUtil.DBNAME, seq_rep);
//				if(v_rep != null){
//					System.out.println("此流程已关联指标");
//					return "have_zhibiao";
//				}
//				String sql_del_rep = "delete from TB_PROCESS_REP where PROCESSID = " + jsonObject.getInt("pID");
//				del_record.add(sql_del_rep);
				
			}else if(deep.equals("1")){
				String seq = "select * from tb_process_lifecycle where processID = "+ jsonObject.getInt("pID");
				System.out.println(seq);
							Vector v = dao.getDataSet(ConstUtil.DBNAME, seq);
							if(v != null){
								return "have_xia";
							} 
							String sql_del = "delete from tb_process where PROCESSID = " + jsonObject.getInt("pID");
							del_record.add(sql_del);
//							String seq_rep = "select * from TB_PROCESS_LIFECYCLE_REP where PROCESSID = "+ jsonObject.getInt("pID");
//							Vector v_rep = dao.getDataSet(ConstUtil.DBNAME, seq_rep);
//							if(v_rep != null){
//								System.out.println("此流程已关联指标");
//								return "have_zhibiao";
//							}
//							String sql_del_rep = "delete from TB_PROCESS_REP where PROCESSID = " + jsonObject.getInt("pID");
//							del_record.add(sql_del_rep);
							
			}else if(deep.equals("2")){
				String seq = "select * from tb_link where lifecycleID = "+ jsonObject.getInt("pID");
				Vector v = dao.getDataSet(ConstUtil.DBNAME, seq);
				if(v != null){
					return "have_xia";
				} 
				String sql_del = "delete from tb_process_lifecycle where lifecycleID = " + jsonObject.getInt("pID");
				del_record.add(sql_del);
//				String seq_rep = "select * from TB_LINK_REP where lifecycleID = "+ jsonObject.getInt("pID");
//				Vector v_rep = dao.getDataSet(ConstUtil.DBNAME, seq_rep);
//				if(v_rep != null){
//					System.out.println("此流程已关联指标");
//					return "have_zhibiao";
//				}
//				String sql_del_rep = "delete from TB_PROCESS_REP where PROCESSID = " + jsonObject.getInt("pID");
//				del_record.add(sql_del_rep);
				
			}else if(deep.equals("3")){
				String seq = "select * from TB_POINT where LINKID = "+ jsonObject.getInt("pID");
							Vector v = dao.getDataSet(ConstUtil.DBNAME, seq);
							if(v != null){
								return "have_xia";
							} 				
				String sql_del = "delete from TB_LINK where LINKID = " + jsonObject.getInt("pID");
				del_record.add(sql_del);
//				String seq_rep = "select * from TB_LINK_REP where LINKID = "+ jsonObject.getInt("pID");
//				Vector v_rep = dao.getDataSet(ConstUtil.DBNAME, seq_rep);
//				if(v_rep != null){
//					System.out.println("此环节已关联指标");
//					return "have_zhibiao";
//				} 	
//				String sql_del_rep = "delete from TB_LINK_REP where LINKID = " + jsonObject.getInt("pID");
//				del_record.add(sql_del_rep);
			}else if(deep.equals("4")||deep.equals("5")){
				String sql_del = "delete from TB_POINT where POINTID = " + jsonObject.getInt("pID");
				del_record.add(sql_del);
				String seq_rep = "select count(1) from TB_POINT_REP where POINTID = "+ jsonObject.getInt("pID");
				String v_rep = dao.getDataValue(ConstUtil.DBNAME, seq_rep);
				int total=Integer.valueOf(v_rep);
				if(total>0){
					return "have_zhibiao";
				}
//				String sql_del_rep = "delete from TB_POINT_REP where POINTID = " + jsonObject.getInt("pID");
//				del_record.add(sql_del_rep);
			}
	     	Boolean bRet = dao.execCommand(ConstUtil.DBNAME, del_record);
			if (bRet == true) {
				return "ok";
			} else {
				return "wrong";
			}

	} catch (RuntimeException e){
			e.printStackTrace();
				return "wrong";
		}
	}

	// 加载数据
	public String getGrid(String start, String limit,
			String KeyWord_cx1,String KeyWord_cx2, String KeyWord_depth, String KeyWord_id) {
        String [] myid=KeyWord_id.split("_");
        KeyWord_id=myid[myid.length-1];		
		String res = "";
		DAO dao = new DAO();
		try {
			List<PmangaeVO> lstRes = new ArrayList<PmangaeVO>();
			int iStart = Integer.parseInt(start);
			int iPageSize = Integer.parseInt(limit);
			int iPage =  iStart/iPageSize + 1;
			StringBuffer str = new StringBuffer();
			//通过限定条件，获取用户所需数据
			if(KeyWord_depth.equals("")||KeyWord_depth.equals("0")){
			str.append("select * from tb_domain where 1 = 1");
				if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
					str.append(" and DOMAINCODE like '%" + KeyWord_cx1 + "%'");
				}	
				if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
					str.append(" and DOMAINNAME like '%" + KeyWord_cx2 + "%'");
				}				
			Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(),iPage,iPageSize);
			if (v != null) {
				for (int i = 0; i < v.size(); i++) {
					Hashtable hashRows = (Hashtable) v.get(i);
					PmangaeVO proVO = new PmangaeVO();
					proVO.setpID((String) hashRows.get("DOMAINID"));
					proVO.setPcode((String) hashRows.get("DOMAINCODE"));
					proVO.setPname((String) hashRows.get("DOMAINNAME"));
					proVO.setPdesc((String) hashRows.get("DOMAINDESC"));
					lstRes.add(proVO);
				}
			}
			
			JSONArray json = new JSONArray();
			StringBuffer str1 = new StringBuffer();
			str1.append("select count(1) CNT from TB_DOMAIN where 1 = 1 ");
				if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
					str.append(" and DOMAINCODE like '%" + KeyWord_cx1 + "%'");
				}	
				if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
					str1.append(" and DOMAINNAME like '%" + KeyWord_cx2 + "%'");
				}
			
			String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
			json = JSONArray.fromObject(lstRes);
			res = "{totalCount:" + totalCount + ",data:" + json.toString()
					+ "}";
				}
			
			if(KeyWord_depth.equals("1")){
			str.append("select a.*,b.DOMAINNAME from TB_PROCESS a left join tb_domain b on a.domainID = b.domainID ");
			str.append(" where a.domainID = " + KeyWord_id);
				if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
					str.append(" and PROCESSCODE like '%" + KeyWord_cx1.toUpperCase() + "%'");
				}
				if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
					str.append(" and PROCESSNAME like '%" + KeyWord_cx2 + "%'");
				}	
			Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(),iPage,iPageSize);
			if (v != null) {
				for (int i = 0; i < v.size(); i++) {
					Hashtable hashRows = (Hashtable) v.get(i);
					PmangaeVO proVO = new PmangaeVO();
					proVO.setpID((String) hashRows.get("PROCESSID"));
					proVO.setPcode((String) hashRows.get("PROCESSCODE"));
					proVO.setPname((String) hashRows.get("PROCESSNAME"));
					proVO.setPdesc((String) hashRows.get("PROCESSDESC"));
					proVO.setPlink((String) hashRows.get("DOMAINID"));
					proVO.setPname_link((String) hashRows.get("DOMAINNAME"));
					lstRes.add(proVO);
				}
			}
			JSONArray json = new JSONArray();
			StringBuffer str1 = new StringBuffer();
			str1.append("select count(1) CNT from TB_PROCESS where domainID = " + KeyWord_id);
				if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
					str1.append(" and PROCESSCODE like '%" + KeyWord_cx1.toUpperCase() + "%'");
				}
				if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
					str1.append(" and PROCESSNAME like '%" + KeyWord_cx2 + "%'");
				}
				
			String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
			json = JSONArray.fromObject(lstRes);
			res = "{totalCount:" + totalCount + ",data:" + json.toString()
					+ "}";
				}
			if(KeyWord_depth.equals("2")){
					str.append("select a.*,b.processname from tb_process_lifecycle a left join tb_process b on a.processid = b.processid ");
					str.append(" where a.processid = " + KeyWord_id);
					if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
						str.append(" and lifecycleCode like '%" + KeyWord_cx1 + "%'");
					}	
					if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
						str.append(" and a.lifecycleName like '%" + KeyWord_cx2 + "%'");
					}				
				Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(),iPage,iPageSize);
				if (v != null) {
					for (int i = 0; i < v.size(); i++) {
						Hashtable hashRows = (Hashtable) v.get(i);
						PmangaeVO proVO = new PmangaeVO();
						proVO.setpID((String) hashRows.get("LIFECYCLEID"));
						proVO.setPcode((String) hashRows.get("LIFECYCLECODE"));
						proVO.setPname((String) hashRows.get("LIFECYCLENAME"));
						proVO.setPdesc((String) hashRows.get("LIFECYCLEDESC"));
						proVO.setPlink((String) hashRows.get("PROCESSID"));
						proVO.setPname_link((String) hashRows.get("PROCESSNAME"));
						lstRes.add(proVO);
					}
				}
				
				JSONArray json = new JSONArray();
				StringBuffer str1 = new StringBuffer();
				str1.append("select count(1) CNT from tb_process_lifecycle where processid = " + KeyWord_id);
					if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
						str.append(" and lifecycleCode like '%" + KeyWord_cx1 + "%'");
					}
					if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
						str1.append(" and lifecycleName like '%" + KeyWord_cx2 + "%'");
					}
				String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
				json = JSONArray.fromObject(lstRes);
				res = "{totalCount:" + totalCount + ",data:" + json.toString()
						+ "}";
					}			
				if(KeyWord_depth.equals("3")){
					str.append("select a.*,b.lifecycleName from tb_link a left join tb_process_lifecycle b on a.lifecycleID = b.lifecycleID ");
					str.append(" where a.lifecycleID = " + KeyWord_id);
					if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
						str.append(" and a.LINKCODE like '%" + KeyWord_cx1.toUpperCase() + "%'");
					}
					if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
						str.append(" and a.LINKNAME like '%" + KeyWord_cx2 + "%'");
					}				
				Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(),iPage,iPageSize);
				if (v != null) {
					for (int i = 0; i < v.size(); i++) {
						Hashtable hashRows = (Hashtable) v.get(i);
						PmangaeVO proVO = new PmangaeVO();
						proVO.setpID((String) hashRows.get("LINKID"));
						proVO.setPcode((String) hashRows.get("LINKCODE"));
						proVO.setPname((String) hashRows.get("LINKNAME"));
						proVO.setPdesc((String) hashRows.get("LINKDESC"));
						proVO.setPlink((String) hashRows.get("LIFECYCLEID"));
						proVO.setPname_link((String) hashRows.get("LIFECYCLENAME"));
						lstRes.add(proVO);
					}
				}
				
				JSONArray json = new JSONArray();
				StringBuffer str1 = new StringBuffer();
				str1.append("select count(1) CNT from TB_LINK where lifecycleID = " + KeyWord_id);

					if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
						str1.append(" and LINKCODE like '%" + KeyWord_cx1.toUpperCase() + "%'");
					}
					if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
						str1.append(" and LINKNAME like '%" + KeyWord_cx2 + "%'");
					}
				
				String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
				json = JSONArray.fromObject(lstRes);
				res = "{totalCount:" + totalCount + ",data:" + json.toString()
						+ "}";
					}
				
				if(KeyWord_depth.equals("4")){
					str.append("select a.*,b.linkname from TB_POINT a left join TB_LINK b on a.linkid=b.linkid");
					str.append(" where a.linkid = " + KeyWord_id);
					if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
						str.append(" and a.POINTCODE like '%" + KeyWord_cx1.toUpperCase() + "%'");
					}
					if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
						str.append(" and a.POINTNAME like '%" + KeyWord_cx2 + "%'");
					}				
				Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(),iPage,iPageSize);
				if (v != null) {
					for (int i = 0; i < v.size(); i++) {
						Hashtable hashRows = (Hashtable) v.get(i);
						PmangaeVO proVO = new PmangaeVO();
						proVO.setpID((String) hashRows.get("POINTID"));
						proVO.setPcode((String) hashRows.get("POINTCODE"));
						proVO.setPname((String) hashRows.get("POINTNAME"));
						proVO.setPdesc((String) hashRows.get("POINTDESC"));
						proVO.setPlink((String) hashRows.get("LINKID"));
						proVO.setPname_link((String) hashRows.get("LINKNAME"));
						lstRes.add(proVO);
					}
				}
				
				JSONArray json = new JSONArray();
				StringBuffer str1 = new StringBuffer();
				str1.append("select count(1) CNT from TB_POINT where LINKID = " + KeyWord_id);

					if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
						str1.append(" and POINTCODE like '%" + KeyWord_cx1.toUpperCase() + "%'");
					}
					if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
						str1.append(" and POINTNAME like '%" + KeyWord_cx2 + "%'");
					}
				
				String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
				System.out.println("		符合该查询条件数据的总条数为：" + totalCount); 
				json = JSONArray.fromObject(lstRes);
				res = "{totalCount:" + totalCount + ",data:" + json.toString()
						+ "}";
					}
				if(KeyWord_depth.equals("5")){
					str.append("select a.*,b.linkname from TB_POINT a left join TB_LINK b on a.linkid=b.linkid");
					str.append(" where a.POINTID = " + KeyWord_id);
					if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
						str.append(" and a.POINTCODE like '%" + KeyWord_cx1.toUpperCase() + "%'");
					}
					if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
						str.append(" and a.POINTNAME like '%" + KeyWord_cx2 + "%'");
					}				
				Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(),iPage,iPageSize);
				if (v != null) {
					for (int i = 0; i < v.size(); i++) {
						Hashtable hashRows = (Hashtable) v.get(i);
						PmangaeVO proVO = new PmangaeVO();
						proVO.setpID((String) hashRows.get("POINTID"));
						proVO.setPcode((String) hashRows.get("POINTCODE"));
						proVO.setPname((String) hashRows.get("POINTNAME"));
						proVO.setPdesc((String) hashRows.get("POINTDESC"));
						proVO.setPlink((String) hashRows.get("LINKID"));
						proVO.setPname_link((String) hashRows.get("LINKNAME"));
						lstRes.add(proVO);
					}
				}
				JSONArray json = new JSONArray();
				StringBuffer str1 = new StringBuffer();
				str1.append("select count(1) CNT from TB_POINT where POINTID = " + KeyWord_id);

					if (KeyWord_cx1 != null && !KeyWord_cx1.equals("")) {
						str1.append(" and POINTCODE like '%" + KeyWord_cx1.toUpperCase() + "%'");
					}
					if (KeyWord_cx2 != null && !KeyWord_cx2.equals("")) {
						str1.append(" and POINTNAME like '%" + KeyWord_cx2 + "%'");
					}
				
				String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
				json = JSONArray.fromObject(lstRes);
				res = "{totalCount:" + totalCount + ",data:" + json.toString()
						+ "}";
					}
		} catch (Exception ex) {
			ex.printStackTrace();
			return "wrong";
		}
		return res;
	}
}
